/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controlador;


import Dao.DaoSocio;
import Modelo.Listas;
import Modelo.Socio;
import Vista.JFrameConsulSocio;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

public class ControladorConsulSocio implements MouseListener 
{
    private String cedula;
    private JFrameConsulSocio formConsulSocio;
    

    public ControladorConsulSocio() throws SQLException 
    {
        
        formConsulSocio = new JFrameConsulSocio();
        //formConsulSocio.setLocationRelativeTo(null);
        formConsulSocio.setVisible(true);
        formConsulSocio.agregarListener(this);
        cargarGridSocio();
    }
    
    public String getCedula() {
        return cedula;
    }

    private void cargarGridSocio() throws SQLException {
        int Fila = 0;
        ResultSet registroSocio;
        DaoSocio daoSocio = new DaoSocio();
        registroSocio = daoSocio.ConsultarSocio();
        
        while (registroSocio.next()) 
        {
            

            formConsulSocio.getjTableConsulSocio().setValueAt(registroSocio.getString("cedula"), Fila, 0);
            formConsulSocio.getjTableConsulSocio().setValueAt(registroSocio.getString("nombre"), Fila, 1);
            formConsulSocio.getjTableConsulSocio().setValueAt(registroSocio.getString("cargo"), Fila, 2);
            formConsulSocio.getjTableConsulSocio().setValueAt(registroSocio.getString("codigocooperativa"), Fila, 3);
            Fila++;
        }
    }
    
    

    @Override
    public void mouseClicked(MouseEvent e) {
        
        if(e.getSource().equals(formConsulSocio.getjTableConsulSocio()))
        {
            CedulaTabla(e);
        }
        
    }

    public void CedulaTabla(MouseEvent e)
    {
        int fila;
        cedula="";
        fila = formConsulSocio.getjTableConsulSocio().rowAtPoint(e.getPoint());
        if(fila>-1)
        {
           cedula = String.valueOf(formConsulSocio.getjTableConsulSocio().getValueAt(fila, 1));
           formConsulSocio.dispose();
           notify();
           //System.out.println(cedula);
        }
        
        
    }

    public JFrameConsulSocio getFormConsulSocio() {
        return formConsulSocio;
    }

    @Override
    public void mousePressed(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
